import { ref } from 'vue'
import { defineStore } from 'pinia'
import { useLifeService } from '@/api/life'

export const useLifeStore = defineStore('lifequality', () => {
  const life = ref({})
  const getLife = async (id) => {
    const res = await useLifeService.get(id)
    if (res.data.data === null) {
      life.value = {}
    } else {
      life.value = res.data.data
    }
  }
  const setLife = async (data) => {
    const res = await useLifeService.put(data)
    if (res.data.code === 20031) return true
    else return false
  }
  const addLife = async (data) => {
    const res = await useLifeService.post(data)
    if (res.data.code === 20011) return true
    return false
  }

  return { life, getLife, setLife, addLife }
})
